import java.io.*;

public class Test {
    public static void main(String[] args) {
//        execLinuxShell(new String[]{"cd", "/Users/kaily/code/blue"});
        int result = buildApp("com.blue.shine", "v4.0.2", "14");
        System.out.println(result);
    }

    public static int buildApp(String applicationId, String versionName, String versionCode) {
        //执行程序
        String exe = "/usr/local/bin/python3.6";
        //执行的脚本命令
        String command = "/root/android/code/web/blue_custome/blue_custome.py";
        //执行参数
        String applicationParameter = String.format("applicationId=%s", applicationId);
        String versionNameParameter = String.format("versionName=%s", versionName);
        String versionCodeParameter = String.format("versionCode=%s", versionCode);
        String[] cmdArr = new String[]{exe, command, applicationParameter, versionNameParameter, versionCodeParameter};
        return execLinuxShell(cmdArr);
    }

    public static int execLinuxShell(String[] cmdArr) {
        Runtime runtime = Runtime.getRuntime();
        Process process;
        BufferedReader br = null;
        try {
            process = runtime.exec(cmdArr);
            br = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String inline;
            while ((inline = br.readLine()) != null) {
                System.out.println(inline);
            }
            br.close();
            br = new BufferedReader(new InputStreamReader(process.getErrorStream()));    //错误信息
            while ((inline = br.readLine()) != null) {
                System.out.println(inline);
            }
        } catch (Exception e) {
//            LOGGER.error(e.getMessage(), e);
//            session.getBasicRemote().sendText("<font color='red'>" + e.getMessage() + "</font>");
        } finally {
//            if (br != null)
//                br.close();
//            if (wr != null)
//                wr.close();
//            session.getBasicRemote().sendText("End.");
        }
        return -1;
    }
}
